#include "uECC.h"

static int sign_init(void)
{
	pr_info("sign init...\n");
    int i;
    uint8_t private[32] = {0};
    uint8_t public[64] = {0};
    uint8_t hash[32] = {0};
    uint8_t sig[64] = {0};

    const struct uECC_Curve_t *curves;
    curves = uECC_secp256r1();
    printk("Testing ecdsa signatures\n");

    for (i = 0; i < 5; ++i) {
        if (!uECC_make_key(public, private, curves)) {
            printk("uECC_make_key() failed\n");
            return 1;
        }
        memcpy(hash, public, sizeof(hash));

        if (!uECC_sign(private, hash, sizeof(hash), sig, curves)) {
            printk("uECC_sign() failed\n");
            return 1;
        }

        print_hex_dump(KERN_CONT, "ecdsa_sign:", DUMP_PREFIX_OFFSET, 16, 1, sig, 64, false);

        if (!uECC_verify(public, hash, sizeof(hash), sig, curves)) {
            printk("uECC_verify() failed\n");
            return 1;
        } else {
            printk("verfiy success!\n");
        }
    }
	return 0;
}

static void sign_exit(void) {
	pr_info("Goodbye cruel world...\n");
}

module_init(sign_init);
module_exit(sign_exit);

MODULE_LICENSE("GPL");
